package com.scau.meetingbook.pojo;

import com.baomidou.mybatisplus.annotation.IdType;

import java.time.*;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 会议室预定表
 * </p>
 *
 * @author scau
 * @since 2025-06-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="RoomReservations对象", description="会议室预定表")
public class RoomReservations implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "预定ID")
    @TableId(value = "reservation_id")
    private String reservationId;

    @ApiModelProperty(value = "会议室ID")
    private Integer roomId;

    @ApiModelProperty(value = "用户ID")
    private Integer userId;

    @ApiModelProperty(value = "预定日期")
    private Date reservationDate;

    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    @ApiModelProperty(value = "参会人数")
    private Integer participants;

    @ApiModelProperty(value = "所需设备")
    private String requiredEquipment;

    @ApiModelProperty(value = "预定状态：pending（待支付）、confirmed（已支付）、cancelled（已取消）")
    private String reservationStatus;

    @ApiModelProperty(value = "支付截止时间")
    private Date paymentDeadline;

    @ApiModelProperty(value = "创建人")
    private Integer createBy;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    private Integer updateBy;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    public String getReservationId() {
        return reservationId;
    }

    public void setReservationId(String reservationId) {
        this.reservationId = reservationId;
    }

    public Integer getRoomId() {
        return roomId;
    }

    public void setRoomId(Integer roomId) {
        this.roomId = roomId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Date getReservationDate() {
        return reservationDate;
    }

    public void setReservationDate(Date reservationDate) {
        this.reservationDate = reservationDate;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getParticipants() {
        return participants;
    }

    public void setParticipants(Integer participants) {
        this.participants = participants;
    }

    public String getRequiredEquipment() {
        return requiredEquipment;
    }

    public void setRequiredEquipment(String requiredEquipment) {
        this.requiredEquipment = requiredEquipment;
    }

    public String getReservationStatus() {
        return reservationStatus;
    }

    public void setReservationStatus(String reservationStatus) {
        this.reservationStatus = reservationStatus;
    }

    public Date getPaymentDeadline() {
        return paymentDeadline;
    }

    public void setPaymentDeadline(Date paymentDeadline) {
        this.paymentDeadline = paymentDeadline;
    }

    public Integer getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Integer createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Integer updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * 合并日期和时间创建完整的开始时间
     */
    public Date getFullStartDateTime() {
        if (reservationDate == null || startTime == null) {
            return null;
        }

        LocalDate datePart = reservationDate.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDate();

        LocalTime timePart = startTime.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalTime();

        LocalDateTime fullDateTime = LocalDateTime.of(datePart, timePart);
        return Date.from(fullDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    /**
     * 计算会议持续时间（小时数）
     * @return 持续小时数
     */
    public Double getDurationHours() {
        if (reservationDate == null || startTime == null || endTime == null) {
            return null;
        }

        // 合并日期和时间
        LocalDateTime startDateTime = combineDateAndTime(reservationDate, startTime);
        LocalDateTime endDateTime = combineDateAndTime(reservationDate, endTime);

        // 计算持续时间（小时）
        Duration duration = Duration.between(startDateTime, endDateTime);
        return duration.toMinutes() / 60.0; // 精确到分钟的小数
    }
    /**
     * 合并日期和时间
     */
    private LocalDateTime combineDateAndTime(Date datePart, Date timePart) {
        LocalDate date = datePart.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDate();

        LocalTime time = timePart.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalTime();

        return LocalDateTime.of(date, time);
    }
}
